<?php

class SiteController extends Controller
{
    /**
     * Declares class-based actions.
     */
    public function actions()
    {
        return array(

            // page action renders "static" pages stored under 'protected/views/site/pages'
            // They can be accessed via: index.php?r=site/page&view=FileName
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }


    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex()
    {
        //get feature value
        $criteria=new CDbCriteria;
        $criteria->select =  array("FN_QTC_MULTI_NAME(P.PRODUCT_NAME,P.PRODUCT_ENG_NAME,:LANG_CODE) AS PRODUCT_NAME",
            "FN_QTC_MULTI_NAME(P.SLUG,P.SLUG_ENG,:LANG_CODE) AS SLUG"," 'B' AS TYPE ");
        $criteria->condition = "BEST_SELL_YN = 'Y' ";
        $criteria->alias = "P";
        $criteria->limit = 10;
        $criteria->params =  array(':LANG_CODE'=> Yii::app()->language);
        $bestSeller = Product::model()->with(array("Menu", array("select"=>array("FN_QTC_MULTI_NAME(Menu.MENU_SLUG,Menu.MENU_SLUG_ENG,:LANG_CODE) AS SLUG"))))->findAll($criteria);

        $criteria=new CDbCriteria;
        $criteria->condition = "FEATURE_YN = 'Y' ";
        $feature = Product::model()->with(array("Menu", array("select"=>array("FN_QTC_MULTI_NAME(Menu.MENU_SLUG,Menu.MENU_SLUG_ENG,:LANG_CODE) AS SLUG"))))->findAll($criteria);

        $criteria=new CDbCriteria;
        $criteria->alias = "P";
        $criteria->order = " PRODUCT_CODE DESC";

        $lastest = Product::model()->with(array("Menu", array("select"=>array("FN_QTC_MULTI_NAME(Menu.MENU_SLUG,Menu.MENU_SLUG_ENG,:LANG_CODE) AS SLUG"))))->findAll($criteria);


        // get best seller

        $this->render('index', array("features"=> $feature, "lastests" => $lastest, "bestSellers" => $bestSeller));
    }

    /**
     * This is the action to handle external exceptions.
     */
    public function actionError()
    {
        if ($error = Yii::app()->errorHandler->error) {
            if (Yii::app()->request->isAjaxRequest)
                echo $error['message'];
            else
                $this->render('error', $error);
        }
    }

    /**
     * Displays the contact page
     */
    public function actionContact()
    {
        $this->render('contact');
    }


    /**
     * Displays the contact page
     */
    public function actionAbout()
    {
        $this->render('about');
    }

}